// 用户管理接口
import request from '@/utils/request'
import type { UserResData, queryParams } from './userType'

enum API {
  all_user = '/api/user/page',
  add_user = '/api/user/add',
  update_user = '/api/user/update',
  delete_user = '/api/user/delete',
  delete_users = '/api/user/delete-batch',
  change_user_active = '/api/user/active',
  all_role = '/api/role/page',
}

// 获取学生、教师列表
export const reqAllUser = (params: queryParams) => {
  const queryParams = new URLSearchParams({
    current: params.current.toString(),
    size: params.size.toString(),
    username: params.username || '',
    realname: params.realname || '',
    userType: params.userType
  }).toString()
  const url = `${API.all_user}?${queryParams}`
  return request.get<any, UserResData>(url)
}
// 新增用户、修改用户、分配角色
export const reqAddOrUpdateUser = (data: any) => {
  if (data.id) {
    return request.put<any, any>(API.update_user, data)
  } else {
    return request.post<any, any>(API.add_user, data)
  }
}
// 删除单个用户
export const reqRemoveUser = (id: number, version: number) => {
  return request.delete<any, any>(API.delete_user + `?id=${id}&version=${version}`)
}
// 批量删除
export const reqRemoveUsers = (ids: string, versions: string) => {
  return request.delete<any, any>(API.delete_users + `?ids=${ids}&versions=${versions}`)
}
// 启用/禁用 用户
export const reqChangeActive = (data: any) => {
  return request.put<any, any>(API.change_user_active, data)
}

// 获取全部角色接口
export const reqAllRole = () => {
  return request.get<any, any>(API.all_role)
}
